import("io", true)
import("MPI")

start = (new Date()).getTime();

NRA = 200;
NCA = 200;
NCB = 200;

// Macro to assist creating arrays
Array.Matrix = function(rows, cols) {
    newArray = new Array(rows);
    for (var i=0; i<rows; i++)
    {
        newArray[i] = new Array(cols);
        for (var j=0; j<cols; j++)
            newArray[i][j] = 0.0
    }
    return newArray;
}
Array.prototype = new Array();

b = Array.Matrix(NCA, NCB);
a = Array.Matrix(NRA, NCA);
for (i in a)
    for (j in a[i])
        a[i][j] = parseFloat(i)+parseFloat(j);

for (i in b)
    for (j in b[i])
        b[i][j] = parseFloat(i)*parseFloat(j)+1;

sending = (new Date()).getTime();

// Calculate
c = Array.Matrix(NRA, NCB);
for (k=0; k<NCB; k++) {
    for (i=0; i<NRA; i++) {
        c[i][k] = 0.0;
        for (j=0; j<NCA; j++)
            c[i][k] += a[i][j] * b[j][k];
    }
}

end = (new Date()).getTime();

print("Filling: " + (sending-start) / 1000);
print("Calculating: " + (end-sending) / 1000);
